//
//  LJCMusicCollectionViewCell.m
//  WZLProduct
//
//  Created by 陆静聪 on 16/3/17.
//  Copyright © 2016年 HaiTeng. All rights reserved.
//

#import "LJCMusicCollectionViewCell.h"

@interface LJCMusicCollectionViewCell ()

@property (nonatomic, retain) UIImageView *musicImage;/**< 音乐图片 */
@property (nonatomic, retain) UILabel *nameLabel;/**< 名称 */
@property (nonatomic, retain) UILabel *detailLabel;/**< 描述 */
@property (nonatomic, retain) UIImageView *playImage;/**< 播放 */
@end

@implementation LJCMusicCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createCell];
    }
    return self;
}

/** model赋值 */
- (void)setMusicModel:(LJCMusicModel *)musicModel {

    if (_musicModel != musicModel) {
        _musicModel = musicModel;
        
        [self giveData];
    }
    
}

- (void)giveData {
    
    if (_musicModel.userimg != nil) {
        [_musicImage sd_setImageWithURL:[NSURL URLWithString:_musicModel.userimg] placeholderImage:nil];
        _nameLabel.text = _musicModel.title;
        _detailLabel.text = _musicModel.uname;
        _playImage.hidden = YES;

    } else {
    
    [_musicImage sd_setImageWithURL:[NSURL URLWithString:_musicModel.imgUrl] placeholderImage:nil];
    _nameLabel.text = _musicModel.title;
    _detailLabel.text = _musicModel.uname;
    _playImage.hidden = NO;
    }
    
}

/** 创建Cell */
- (void)createCell  {
    /** 背景图片 */
    _musicImage = [[UIImageView alloc] init];
    [self.contentView addSubview:_musicImage];
    /** 布局 */
    [_musicImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
        make.height.equalTo(_musicImage.mas_width);
    }];
    
    _playImage = [[UIImageView alloc] init];
    [_musicImage addSubview:_playImage];
    [_playImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.offset(-8);
        make.size.mas_equalTo(CGSizeMake(35, 35));
    }];
    _playImage.backgroundColor = [UIColor redColor];
    
    /** 表题 */
    _nameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_nameLabel];
    /** 布局 */
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_musicImage.mas_bottom).offset(10);
        make.right.left.offset(0);
        make.height.mas_equalTo(30);
    }];
    _nameLabel.textAlignment = NSTextAlignmentCenter;
    _nameLabel.font = FONT15;
    
    /** 细节 */
    _detailLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_detailLabel];
    /** 布局 */
    [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nameLabel.mas_bottom).offset(5);
        make.right.left.offset(0);
        make.height.mas_equalTo(20);
    }];
    _detailLabel.textAlignment = NSTextAlignmentCenter;
    _detailLabel.font = FONT12;
    _detailLabel.textColor = [UIColor grayColor];
    _detailLabel.alpha = 0.8;
    
    
}


@end
